<template>
	<view class="page-container">
		<!-- 顶部搜索区域 -->
		<view class="search-section">
			<view class="search-box">
				<text class="iconfont icon-search"></text>
				<input type="text" placeholder="搜索心仪的活动" v-model="searchText" />
			</view>
		</view>

		<!-- 活动分类 -->
		<scroll-view class="category-section" scroll-x="true" show-scrollbar="false">
			<view class="category-list">
				<view 
					class="category-item" 
					v-for="(item, index) in categories" 
					:key="index"
					:class="{ active: currentCategory === item.id }"
					@click="selectCategory(item.id)"
				>
					<image :src="item.icon" mode="aspectFit" class="category-icon"></image>
					<text>{{ item.name }}</text>
				</view>
			</view>
		</scroll-view>

		<!-- 活动列表 -->
		<scroll-view class="activity-list" scroll-y="true" @scrolltolower="loadMore">
			<view class="activity-card" v-for="(item, index) in activities" :key="index" @click="viewActivity(item)">
				<image class="activity-image" :src="item.image" mode="aspectFill"></image>
				<view class="category-tags">
					<view class="category-tag" v-for="(category, idx) in item.categories" :key="idx">
						{{ category.name }}
					</view>
				</view>
				<view class="activity-info">
					<view class="activity-title">{{ item.title }}</view>
					<view class="activity-desc">{{ item.description }}</view>
					<view class="activity-meta">
						<view class="meta-item">
							<text class="iconfont icon-location"></text>
							<text>{{ item.location }}</text>
						</view>
						<view class="meta-item">
							<text class="iconfont icon-time"></text>
							<text>{{ item.time }}</text>
						</view>
					</view>
					<view class="activity-footer">
						<view class="price">¥{{ item.price }}</view>
						<view class="status" :class="item.status">{{ item.statusText }}</view>
					</view>
				</view>
			</view>
		</scroll-view>

		<tabbarVue tabIndex="2"></tabbarVue>
	</view>
</template>

<script>
	import tabbarVue from '../../components/tabbar.vue'
	export default {
		data() {
			return {
				searchText: '',
				currentCategory: 0,
				categories: [
					{ id: 0, name: '全部', icon: '/static/icons/all.png' },
					{ id: 1, name: '约会', icon: '/static/icons/date.png' },
					{ id: 2, name: '聚会', icon: '/static/icons/party.png' },
					{ id: 3, name: '运动', icon: '/static/icons/sports.png' },
					{ id: 4, name: '旅行', icon: '/static/icons/travel.png' },
					{ id: 5, name: '美食', icon: '/static/icons/food.png' },
					{ id: 6, name: '文化', icon: '/static/icons/culture.png' }
				],
				activities: [
					{
						title: '周末下午茶约会',
						description: '精致下午茶,浪漫音乐,优雅环境,邂逅美好',
						location: '杭州市西湖区金融城',
						time: '2024-03-20 14:00',
						price: '128',
						image: 'https://cdn.uviewui.com/uview/swiper/swiper1.png',
						status: 'ongoing',
						statusText: '报名中',
						categories: [
							{ name: '约会', id: 1 },
							{ name: '美食', id: 5 }
						]
					},
					{
						title: '户外徒步交友',
						description: '登山健身,感受大自然,结识志同道合的朋友',
						location: '杭州市西湖区满觉陇',
						time: '2024-03-21 09:00',
						price: '68',
						image: 'https://cdn.uviewui.com/uview/swiper/swiper2.png',
						status: 'ongoing',
						statusText: '报名中',
						categories: [
							{ name: '运动', id: 3 },
							{ name: '聚会', id: 2 },
							{ name: '旅行', id: 4 }
						]
					},
					{
						title: '密室逃脱团建',
						description: '紧张刺激的密室逃脱,培养默契与友情',
						location: '杭州市拱墅区运河上街',
						time: '2024-03-22 13:00',
						price: '98',
						image: 'https://cdn.uviewui.com/uview/swiper/swiper3.png',
						status: 'full',
						statusText: '已满员',
						categories: [
							{ name: '聚会', id: 2 },
							{ name: '文化', id: 6 }
						]
					}
				],
				page: 1,
				loading: false
			}
		},
		methods: {
			selectCategory(id) {
				this.currentCategory = id
				// TODO: 根据分类加载活动
			},
			viewActivity(item) {
				uni.navigateTo({
					url: '/pages/find/details',
					success: (res) => {
						console.log('跳转成功');
					},
					fail: (err) => {
						console.error('跳转失败', err);
					}
				})
			},
			loadMore() {
				if (this.loading) return
				this.loading = true
				// TODO: 加载更多活动
				setTimeout(() => {
					this.loading = false
				}, 1000)
			}
		},
		components: {
			tabbarVue
		}
	}
</script>

<style lang="scss">
.page-container {
	min-height: 100vh;
	background: #f8f9fa;
	
	.search-section {
		padding: 20rpx 30rpx;
		background: #fff;
		
		.search-box {
			display: flex;
			align-items: center;
			background: #f5f5f5;
			padding: 16rpx 24rpx;
			border-radius: 32rpx;
			
			.icon-search {
				font-size: 32rpx;
				color: #999;
				margin-right: 12rpx;
			}
			
			input {
				flex: 1;
				font-size: 28rpx;
				color: #333;
				
				&::placeholder {
					color: #999;
				}
			}
		}
	}
	
	.category-section {
		background: #fff;
		padding: 20rpx 0;
		white-space: nowrap;
		
		.category-list {
			padding: 0 20rpx;
			display: inline-flex;
			
			.category-item {
				display: flex;
				flex-direction: column;
				align-items: center;
				margin-right: 40rpx;
				
				.category-icon {
					width: 80rpx;
					height: 80rpx;
					margin-bottom: 8rpx;
				}
				
				text {
					font-size: 24rpx;
					color: #666;
				}
				
				&.active {
					text {
						color: #ff69b4;
						font-weight: 500;
					}
				}
			}
		}
	}
	
	.activity-list {
		padding: 20rpx;
		height: calc(100vh - 320rpx);
		
		.activity-card {
			background: #fff;
			border-radius: 16rpx;
			overflow: hidden;
			margin-bottom: 20rpx;
			box-shadow: 0 4rpx 16rpx rgba(0,0,0,0.05);
			position: relative;
			
			.category-tags {
				position: absolute;
				top: 20rpx;
				left: 20rpx;
				display: flex;
				flex-wrap: wrap;
				gap: 12rpx;
				z-index: 1;
				
				.category-tag {
					padding: 8rpx 20rpx;
					background: rgba(0,0,0,0.6);
					color: #fff;
					font-size: 24rpx;
					border-radius: 24rpx;
					backdrop-filter: blur(4px);
					
					&:nth-child(1) {
						background: rgba(255,105,180,0.8);
					}
					
					&:nth-child(2) {
						background: rgba(64,158,255,0.8);
					}
					
					&:nth-child(3) {
						background: rgba(103,194,58,0.8);
					}
				}
			}
			
			.activity-image {
				width: 100%;
				height: 320rpx;
			}
			
			.activity-info {
				padding: 20rpx;
				
				.activity-title {
					font-size: 32rpx;
					font-weight: 600;
					color: #333;
					margin-bottom: 8rpx;
				}
				
				.activity-desc {
					font-size: 26rpx;
					color: #666;
					margin-bottom: 16rpx;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;
					overflow: hidden;
				}
				
				.activity-meta {
					display: flex;
					margin-bottom: 16rpx;
					
					.meta-item {
						display: flex;
						align-items: center;
						margin-right: 24rpx;
						
						.iconfont {
							font-size: 24rpx;
							color: #999;
							margin-right: 4rpx;
						}
						
						text {
							font-size: 24rpx;
							color: #999;
						}
					}
				}
				
				.activity-footer {
					display: flex;
					justify-content: space-between;
					align-items: center;
					
					.price {
						font-size: 36rpx;
						font-weight: 600;
						color: #ff69b4;
						
						&::before {
							content: '¥';
							font-size: 24rpx;
						}
					}
					
					.status {
						padding: 4rpx 16rpx;
						border-radius: 24rpx;
						font-size: 24rpx;
						
						&.ongoing {
							background: rgba(255,105,180,0.1);
							color: #ff69b4;
						}
						
						&.full {
							background: #f5f5f5;
							color: #999;
						}
					}
				}
			}
		}
	}
}
</style>